<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="../js/vue.min.js"></script>
    <!-- 引入样式 -->
    <link href="../ele-2.15.7/theme-chalk/index.css" rel="stylesheet">
    <!-- 引入组件库 -->
    <script src="../ele-2.15.7/index.js"></script>

</head>
<body>
<div id="app">
    <el-container>
        <el-header><h1>xxxxx后台管理系统</h1></el-header>
        <el-container>
            <el-aside style="width: 200px">
                <el-menu
                        @select="selectMenu"
                        class="el-menu-vertical-demo"
                        default-active="2">
                    <el-menu-item :index="menu.name" v-for="menu in menus">
                        <i class="el-icon-location"></i>
                        <span>{{menu.name}}</span>
                    </el-menu-item>
                </el-menu>
            </el-aside>
            <el-main>
                <el-tabs style="height: 100%" type="border-card" v-model="currentTab">
                    <el-tab-pane :key="tab.name" :label="tab.name"
                                 :name="tab.name" v-for=" tab in tabs">
                        <iframe :src="tab.url" height="100%" width="100%"></iframe>
                    </el-tab-pane>
                </el-tabs>
            </el-main>
        </el-container>
    </el-container>
</div>

<script>
    var v = new Vue({
        el: "#app",
        data: {
            menus: [
                {name: "页面布局", url: "layout.html"},
                {name: "分页控件", url: "../vue/d0311/分页.html"},
                {name: "折叠面板", url: "../vue/d0311/折叠面板.html"},
                {name: "分页查询", url: "../vue/d0312/分页查询.html"},
                {name: "图书管理", url: "图书管理.html"}
            ],
            tabs: [ ],
            currentTab: ""

        },
        methods: {
            selectMenu(name) {
                //查找是否已经打开该页
                let tab = this.tabs.find(tab => {
                    if (tab.name == name) {
                        return tab;
                    }
                })
                //如果tab不为undefined,表示已经打开tab
                if (tab) {
                    //直接选中该变迁
                    this.currentTab = name;
                    return;
                }
                //在菜单数组中查找菜单对象
                this.menus.forEach(menu => {
                    if (menu.name == name) {
                        this.tabs.push({
                            name: name,
                            url: menu.url
                        });
                        //设置当前页
                        this.currentTab = name;
                    }
                })
            }
        }
    })
</script>
</body>
<style>
    html, body, #app {
        height: 100%;
        padding: 0px;
        margin: 0px;
    }

    .el-container {
        height: 100%;
    }

    .el-tabs__content {
        height: calc(100% - 68px);
    }

    .el-tab-pane {
        height: 100%;
    }
</style>
</html>